<?php
namespace app\api\service;
use think\Controller;
use think\Db;
use JPush\Client as JPush;

class JPushApi extends Controller {
    private $app_key = '9baebe668afb510ab482940c';
    private $master_secret = '0215b6500a4ce7408c00c58d';
    // 生成服务单
    public function index($content, $longitude = '', $latitude = '') {
        $client = new JPush($this->app_key, $this->master_secret);

        $push_payload = $client->push()
            ->setPlatform('all')
            ->addAllAudience()
            ->setNotificationAlert($content);
        try {
            $response = $push_payload->send();
        }catch (\JPush\Exceptions\APIConnectionException $e) {
            // try something here
            print $e;
        } catch (\JPush\Exceptions\APIRequestException $e) {
            // try something here
            print $e;
        }
    }
}
